use std::collections::HashMap;

use axum::Json;
use serde_json::Value;

use crate::code;

pub fn get_prefix(suffix:&str) -> Result<String, Json<Value>>{
    let mut map:HashMap<&str, &str> = HashMap::new( );
    let _ = map.insert("doc", "data:application/msword;base64,");
    let _ = map.insert("docx", "data:application/vnd.openxmlformats-officedocument.wordprocessingml.document;base64,");
    let _ = map.insert("xls", "data:application/vnd.ms-excel;base64,");
    let _ = map.insert("xlsx", "data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,");
    let _ = map.insert("pdf", "data:application/pdf;base64,");
    let _ = map.insert("ppt", "data:application/vnd.ms-powerpoint;base64,");
    let _ = map.insert("pptx", "data:application/vnd.openxmlformats-officedocument.presentationml.presentation;base64,");
    let _ = map.insert("txt", "data:text/plain;base64,");
    let _ = map.insert("png", "data:image/png;base64,");
    let _ = map.insert("jpg", "data:image/jpeg;base64,");
    let _ = map.insert("gif", "data:image/gif;base64,");
    let _ = map.insert("svg", "data:image/svg+xml;base64,");
    let _ = map.insert("ico", "data:image/x-icon;base64,");
    let _ = map.insert("bmp", "data:image/bmp;base64,");
    match map.get(suffix) {
        Some(f) => Ok( f.to_string() ),
        None => Err(code::sys_(suffix.to_string() + " 后缀名不存在"))
    }
}
// pub(super) fn _get_prefix_by_name(filename:&str) -> Result<String, Json<Value>>{
//     let suffix = get_suffix(filename.to_string());
//     if suffix.is_none() {
//         Err(code::sys_("后缀名不存在"))
//     }else {
//         let fx = suffix.unwrap();
//         let rs = get_prefix(&fx)?;
//         Ok( rs )
//     }
// }